<template>
	<view class="page page-applystore">
		<view v-if="authStatus == 1" bg-green-5 h-40px lh-40px pl-10px c-white text-lg>恭喜您，店铺开通审核通过</view>
		<view v-else-if="authStatus == 2" bg-red-5 h-40px lh-40px pl-10px c-white text-lg>审核被拒绝</view>
		
		<view v-if="authStatus == 1" py-20px px-10px>
			<view text-base pb-10px>店铺地址为：{{ url }}</view>
			<view text-xs c-gray-4>注：建议您在电脑端浏览器输入该地址进行操作</view>
		</view>

		<view v-if="!authStatus" text-center>
			<view class="icon icon-audit text-6xl c-green-5" py-50px></view>
			<view text="xl">您的申请已提交审核，请耐心等待</view>
			<view pt-20px pb-100px c-gray-4>温馨提示：申请审核将在72时内完成</view>
			<view px-50px>
				<nut-button size="large" type="info" @click="back">返回</nut-button>
			</view>
		</view>

		<view v-else p10px>
			<uni-title type="h3" title="申请信息"></uni-title>
			<view flex items-center justify-between mt10px pb-10px border-b>
				<view min-w-200px> <text color-red-5>*</text> 申请用户名</view>
				<uni-easyinput color-gray v-model="username" :disabled="authStatus == 1" :inputBorder="false" placeholder="请输入用户名 &nbsp;"></uni-easyinput>
			</view>

			<view flex items-center justify-between mt10px pb-10px border-b>
				<view min-w-200px> <text color-red-5>*</text> 密码</view>
				<uni-easyinput color-gray v-model="password" :disabled="authStatus == 1" :inputBorder="false" placeholder="请输入密码 &nbsp;"></uni-easyinput>
			</view>

			<view fixed w-94vw bottom-20px left-3vw v-if="authStatus != 1">
				<button w-full type="primary" rounded-100px :loading="loading" @click="submit">提交申请</button>
			</view>
		</view>
	
	</view>

</template>

<script setup>
	import api from '@/api'
	import { reactive, ref, computed } from 'vue'

	const username = ref('')
	const password = ref('')
	const authStatus = ref(10086)		//0待审核 1审核通过 2拒绝 3未提交
	const url = ref('')
	
	async function initData() {
		const data = await api.checkStoreStatus()
		if(data) {
			authStatus.value = data.status
			if(!data.status || data.status == 3) return
			username.value = data.account_name
			password.value = data.password
			url.value = data.url
		}
	}
	initData()

	const submit = async () => {
		if(!username.value) {
			uni.showToast({ title: '请填写用户名', icon: 'none' })
			return
		}
		if(!password.value) {
			uni.showToast({ title: '请填写密码', icon: 'none' })
			return
		}
		const id = await api.applyStore({
			username: username.value,
			password: password.value
		})
		if(id) {
			authStatus.value = 0
		}
	}
	
</script>

<style lang="scss">
.page-applystore {
	
	.border-b{
		border-bottom: 1px solid #eee;
	}
	.uni-easyinput  {
		text-align: right;
	}
	.input-value-border {
		border: none;
	}

}



</style>
